package com.cyt.servlet.admin;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import com.cyt.dao.impl.GuanLiDaoImpl;
import com.cyt.entity.GuanLI;
import com.cyt.util.BaseServlet;
import com.cyt.util.Result;


public class AdminGuanLiYuanServlet extends BaseServlet {
	
	/**
	 * localhost:8080/shiping/guanLiYuan?reqName=guanLi
	 * @param request
	 * @param response
	 * @throws ServletException
	 * @throws IOException
	 */
	public void guanLi(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		response.setCharacterEncoding("UTF-8");
	    PrintWriter out=response.getWriter();
	    GuanLiDaoImpl gunnDao=new GuanLiDaoImpl();

		String zhanghao=request.getParameter("zhanghao");
		String mima=request.getParameter("mima");
		GuanLI guan= gunnDao.getGuanLiName(zhanghao);
	    
		if(guan==null) {
			out.print(Result.toClient(false, "", "账号错误"));

		}else {
			if(guan.getMima().equals(mima)) {
				HttpSession session = request.getSession();
				session.setAttribute("guan", guan);
				out.print(Result.toClient(true, guan, "登录成功"));
				
			}else {
				out.print(Result.toClient(false, "", "密码错误"));

			}
		}
	     
	    out.flush();
	    out.close();
	}
}
